package com.example.musicwebcon.controller;

import com.example.musicwebcon.model.ResponseMessage;
import com.example.musicwebcon.model.dto.playingListDTO;
import com.example.musicwebcon.service.serviceInterface.IplayingService;
import com.example.musicwebcon.model.playingList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/playing")
public class playingController {
    @Autowired
    IplayingService playingService;
    //增加一条
    @PostMapping
    public ResponseMessage add(@Validated @RequestBody playingListDTO playingListSong){
        playingList song = playingService.add(playingListSong);
        return ResponseMessage.success(song);
    }
    //增加多条
    @PostMapping("/all")
    public ResponseMessage addBatch(@Validated @RequestBody Iterable<playingListDTO> playingLists){
        Iterable<playingList> songs = playingService.addBatch(playingLists);
        return ResponseMessage.success(songs);
    }
    @GetMapping("/{musicId}")
    public ResponseMessage get(@PathVariable String musicId){
        playingList song = playingService.getMusicId(musicId);
        return ResponseMessage.success(song);
    }
    //查询所有
    @GetMapping
    public ResponseMessage getAll(){
        Iterable<playingList> songs = playingService.getALl();
        return ResponseMessage.success(songs);
    }

    @GetMapping("/allsortBysongIndex")
    public ResponseMessage getAllBySongIndex(){
        Iterable<playingList> songs = playingService.getALlBysongIndex();
        return ResponseMessage.success(songs);
    }

    //修改
    @PutMapping
    public ResponseMessage edit(@Validated @RequestBody playingListDTO playingListSong){
        playingList song = playingService.edit(playingListSong);
        return ResponseMessage.success(song);
    }

    //删除歌曲
    @DeleteMapping("{musicId}")
    public ResponseMessage delete(@PathVariable String musicId){
        playingService.deleteMusicId(musicId);
        return ResponseMessage.success(null);
    }
    @DeleteMapping("/deleteall")
    public ResponseMessage deleteAll(){
        playingService.deleteAll();
        return ResponseMessage.success(null);
    }
}
